﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TicketSystem
{
    public partial class Form_SetDefaultPrinter : Form
    {
        public Form_SetDefaultPrinter()
        {
            InitializeComponent();
            InitprinterComboBox(); //初始化打印机下拉列表选项            
        }
        
        private void InitprinterComboBox()
        {
            List<String> list = Common.PrintDataGridView.GetLocalPrinters(); //获得系统中的打印机列表
            foreach (String s in list)
            {
                printerComboBox.Items.Add(s); //将打印机名称添加到下拉框中
            }
            
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (printerComboBox.SelectedItem != null) //判断是否有选中值
            {
                if (Common.Externs.SetDefaultPrinter(printerComboBox.SelectedItem.ToString())) //设置默认打印机
                {
                    MessageBox.Show(printerComboBox.SelectedItem.ToString() + "设置为默认打印机成功！");
                    this.Close();
                }
                else
                {
                    MessageBox.Show(printerComboBox.SelectedItem.ToString() + "设置为默认打印机失败！");
                }
            }
        }

        
    }
}
